home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / GXMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  8.9 KB  |  313 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        GXMath.h
  3.  
  4.      Contains:    QuickDraw GX math routine interfaces.
  5.  
  6.      Version:    Technology:    Quickdraw GX 1.1
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1994-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __GXMATH__
  19. #define __GXMATH__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. #ifndef __FIXMATH__
  28. #include <FixMath.h>
  29. #endif
  30.  
  31.  
  32.  
  33. #if PRAGMA_ONCE
  34. #pragma once
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. #if PRAGMA_IMPORT
  42. #pragma import on
  43. #endif
  44.  
  45. #if PRAGMA_STRUCT_ALIGN
  46.     #pragma options align=mac68k
  47. #elif PRAGMA_STRUCT_PACKPUSH
  48.     #pragma pack(push, 2)
  49. #elif PRAGMA_STRUCT_PACK
  50.     #pragma pack(2)
  51. #endif
  52.  
  53. #if defined(__MWERKS__) && TARGET_CPU_68K
  54.     #pragma push
  55.     #pragma pointers_in_D0
  56. #endif
  57.  
  58.  
  59. struct gxPoint {
  60.     Fixed                             x;
  61.     Fixed                             y;
  62. };
  63. typedef struct gxPoint gxPoint;
  64.  
  65. typedef unsigned short                     gxColorValue;
  66. struct gxPolar {
  67.     Fixed                             radius;
  68.     Fixed                             angle;
  69. };
  70. typedef struct gxPolar gxPolar;
  71.  
  72. struct gxMapping {
  73.     Fixed                             map[3][3];
  74. };
  75. typedef struct gxMapping gxMapping;
  76.  
  77.  
  78. #define    gxColorValue1            ((gxColorValue) 0x0000FFFF)
  79. #define  gxPositiveInfinity        ((long) 0x7FFFFFFFL)
  80. #define    gxNegativeInfinity        ((long) 0x80000000L)
  81.  
  82. EXTERN_API_C( gxMapping *)
  83. CopyToMapping                    (gxMapping *            target,
  84.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0031, 0xA832);
  85.  
  86. EXTERN_API_C( gxMapping *)
  87. InvertMapping                    (gxMapping *            target,
  88.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0032, 0xA832);
  89.  
  90. EXTERN_API_C( gxMapping *)
  91. MapMapping                        (gxMapping *            target,
  92.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0033, 0xA832);
  93.  
  94. EXTERN_API_C( gxMapping *)
  95. MoveMapping                        (gxMapping *            target,
  96.                                  Fixed                     hOffset,
  97.                                  Fixed                     vOffset)                            THREEWORDINLINE(0x303C, 0x0034, 0xA832);
  98.  
  99. EXTERN_API_C( gxMapping *)
  100. MoveMappingTo                    (gxMapping *            target,
  101.                                  Fixed                     hPosition,
  102.                                  Fixed                     vPosition)                            THREEWORDINLINE(0x303C, 0x0035, 0xA832);
  103.  
  104. EXTERN_API_C( gxMapping *)
  105. NormalizeMapping                (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0036, 0xA832);
  106.  
  107. EXTERN_API_C( gxMapping *)
  108. RotateMapping                    (gxMapping *            target,
  109.                                  Fixed                     angle,
  110.                                  Fixed                     xCenter,
  111.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0037, 0xA832);
  112.  
  113. EXTERN_API_C( gxMapping *)
  114. ScaleMapping                    (gxMapping *            target,
  115.                                  Fixed                     hFactor,
  116.                                  Fixed                     vFactor,
  117.                                  Fixed                     xCenter,
  118.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0038, 0xA832);
  119.  
  120. EXTERN_API_C( gxMapping *)
  121. ResetMapping                    (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0039, 0xA832);
  122.  
  123. EXTERN_API_C( gxMapping *)
  124. SkewMapping                        (gxMapping *            target,
  125.                                  Fixed                     skewX,
  126.                                  Fixed                     skewY,
  127.                                  Fixed                     xCenter,
  128.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x003A, 0xA832);
  129.  
  130. EXTERN_API_C( void )
  131. MapPoints                        (const gxMapping *        source,
  132.                                  long                     count,
  133.                                  gxPoint                 vector[])                                THREEWORDINLINE(0x303C, 0x003B, 0xA832);
  134.  
  135. EXTERN_API_C( short )
  136. FirstBit                        (unsigned long             x)                                    THREEWORDINLINE(0x303C, 0x003C, 0xA832);
  137.  
  138. EXTERN_API_C( short )
  139. WideScale                        (const wide *            source)                                THREEWORDINLINE(0x303C, 0x003D, 0xA832);
  140.  
  141. EXTERN_API_C( short )
  142. LinearRoot                        (Fixed                     first,
  143.                                  Fixed                     last,
  144.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003E, 0xA832);
  145.  
  146. EXTERN_API_C( short )
  147. QuadraticRoot                    (Fixed                     first,
  148.                                  Fixed                     control,
  149.                                  Fixed                     last,
  150.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003F, 0xA832);
  151.  
  152. EXTERN_API_C( gxPoint *)
  153. PolarToPoint                    (const gxPolar *        ra,
  154.                                  gxPoint *                xy)                                    THREEWORDINLINE(0x303C, 0x0040, 0xA832);
  155.  
  156. EXTERN_API_C( gxPolar *)
  157. PointToPolar                    (const gxPoint *        xy,
  158.                                  gxPolar *                ra)                                    THREEWORDINLINE(0x303C, 0x0041, 0xA832);
  159.  
  160. EXTERN_API_C( Fract )
  161. FractCubeRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0042, 0xA832);
  162.  
  163. EXTERN_API_C( Fract )
  164. FractDivide                        (Fract                     dividend,
  165.                                  Fract                     divisor)                            THREEWORDINLINE(0x303C, 0x0043, 0xA832);
  166.  
  167. EXTERN_API_C( Fract )
  168. FractMultiply                    (Fract                     multiplicand,
  169.                                  Fract                     multiplier)                            THREEWORDINLINE(0x303C, 0x0044, 0xA832);
  170.  
  171. EXTERN_API_C( Fract )
  172. FractSineCosine                    (Fixed                     degrees,
  173.                                  Fract *                cosine)                                THREEWORDINLINE(0x303C, 0x0045, 0xA832);
  174.  
  175. EXTERN_API_C( Fract )
  176. FractSquareRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0046, 0xA832);
  177.  
  178. EXTERN_API_C( Fixed )
  179. FixedDivide                        (Fixed                     dividend,
  180.                                  Fixed                     divisor)                            THREEWORDINLINE(0x303C, 0x0047, 0xA832);
  181.  
  182. EXTERN_API_C( Fixed )
  183. FixedMultiply                    (Fixed                     multiplicand,
  184.                                  Fixed                     multiplier)                            THREEWORDINLINE(0x303C, 0x0048, 0xA832);
  185.  
  186. /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  187. EXTERN_API_C( long )
  188. MultiplyDivide                    (long                     source,
  189.                                  long                     multiplier,
  190.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x0049, 0xA832);
  191.  
  192. EXTERN_API_C( unsigned long )
  193. Magnitude                        (long                     deltaX,
  194.                                  long                     deltaY)                                THREEWORDINLINE(0x303C, 0x004A, 0xA832);
  195.  
  196. EXTERN_API_C( long )
  197. VectorMultiplyDivide            (long                     count,
  198.                                  const long *            vector1,
  199.                                  long                     step1,
  200.                                  const long *            vector2,
  201.                                  long                     step2,
  202.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x004B, 0xA832);
  203.  
  204.  
  205.  
  206.  
  207. /* wide operations are defined within FixMath.h only for PowerPC */
  208. #if !TARGET_CPU_PPC
  209. EXTERN_API_C( wide *)
  210. WideAdd                            (wide *                    target,
  211.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004C, 0xA832);
  212.  
  213. EXTERN_API_C( short )
  214. WideCompare                        (const wide *            target,
  215.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004D, 0xA832);
  216.  
  217. EXTERN_API_C( wide *)
  218. WideNegate                        (wide *                    target)                                THREEWORDINLINE(0x303C, 0x004E, 0xA832);
  219.  
  220. EXTERN_API_C( wide *)
  221. WideShift                        (wide *                    target,
  222.                                  long                     shift)                                THREEWORDINLINE(0x303C, 0x004F, 0xA832);
  223.  
  224. EXTERN_API_C( unsigned long )
  225. WideSquareRoot                    (const wide *            source)                                THREEWORDINLINE(0x303C, 0x0050, 0xA832);
  226.  
  227. EXTERN_API_C( wide *)
  228. WideSubtract                    (wide *                    target,
  229.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x0051, 0xA832);
  230.  
  231. EXTERN_API_C( wide *)
  232. WideMultiply                    (long                     multiplicand,
  233.                                  long                     multiplier,
  234.                                  wide *                    target)                                THREEWORDINLINE(0x303C, 0x0052, 0xA832);
  235.  
  236. /* returns the quotient */
  237. EXTERN_API_C( long )
  238. WideDivide                        (const wide *            dividend,
  239.                                  long                     divisor,
  240.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0053, 0xA832);
  241.  
  242. /* quotient replaces dividend */
  243. EXTERN_API_C( wide *)
  244. WideWideDivide                    (wide *                    dividend,
  245.                                  long                     divisor,
  246.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0055, 0xA832);
  247.  
  248. #endif  /*  !TARGET_CPU_PPC */
  249.  
  250.  
  251.  
  252. EXTERN_API_C( wide *)
  253. VectorMultiply                    (long                     count,
  254.                                  const long *            vector1,
  255.                                  long                     step1,
  256.                                  const long *            vector2,
  257.                                  long                     step2,
  258.                                  wide *                    dot)                                THREEWORDINLINE(0x303C, 0x0054, 0xA832);
  259.  
  260. EXTERN_API_C( unsigned long )
  261. RandomBits                        (long                     count,
  262.                                  long                     focus)                                THREEWORDINLINE(0x303C, 0x0056, 0xA832);
  263.  
  264. EXTERN_API_C( void )
  265. SetRandomSeed                    (const wide *            seed)                                THREEWORDINLINE(0x303C, 0x0057, 0xA832);
  266.  
  267. EXTERN_API_C( wide *)
  268. GetRandomSeed                    (wide *                    seed)                                THREEWORDINLINE(0x303C, 0x0058, 0xA832);
  269.  
  270.  
  271. #define FixedRound(a)        ((short)((Fixed)(a) + fixed1/2 >> 16))
  272. #define FixedSquareRoot(a)    ((Fixed)FractSquareRoot(a) + 64 >> 7)
  273. #define FixedTruncate(a)        ((short)((Fixed)(a) >> 16))
  274. #define FixedToFract(a)        ((Fract)(a) << 14)
  275. #define FractToFixed(a)        ((Fixed)(a) + 8192L >> 14)
  276. #define FixedToInt(a)       ((short)((Fixed)(a) + fixed1/2 >> 16))
  277. #define IntToFixed(a)       ((Fixed)(a) << 16)
  278. #define FixedToFloat(a)     ((float)(a) / fixed1)
  279. #define FloatToFixed(a)         ((Fixed)((float)(a) * fixed1))
  280. #define FractToFloat(a)     ((float)(a) / fract1)
  281. #define FloatToFract(a)     ((Fract)((float)(a) * fract1))
  282. #define ColorToFract(a)     (((Fract) (a) << 14) + ((Fract)(a) + 2 >> 2))
  283. #define FractToColor(a)     ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  284. #define ff(a)               IntToFixed(a)
  285. #define fl(a)               FloatToFixed(a)
  286.  
  287.  
  288. #if defined(__MWERKS__) && TARGET_CPU_68K
  289.     #pragma pop
  290. #endif
  291.  
  292.  
  293. #if PRAGMA_STRUCT_ALIGN
  294.     #pragma options align=reset
  295. #elif PRAGMA_STRUCT_PACKPUSH
  296.     #pragma pack(pop)
  297. #elif PRAGMA_STRUCT_PACK
  298.     #pragma pack()
  299. #endif
  300.  
  301. #ifdef PRAGMA_IMPORT_OFF
  302. #pragma import off
  303. #elif PRAGMA_IMPORT
  304. #pragma import reset
  305. #endif
  306.  
  307. #ifdef __cplusplus
  308. }
  309. #endif
  310.  
  311. #endif /* __GXMATH__ */
  312.  
  313.